home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / SAT 2.4.0 / SAT / Add-ons / Graphic effects / AlphaSAT.p next >
Encoding:
Text File  |  1997-03-12  |  4.4 KB  |  177 lines  |  [TEXT/PJMM]

  1. {These routines set or reset the alpha channel in 32-bit color. It is of interest}
  2. {when using SAT for mixing graphics with live video, using a video board that}
  3. {supports the alpha channel.}
  4.  
  5. {This unit has not been tested much yet. Use with caution.}
  6.  
  7. {By Ingemar Ragnemalm 1995-1996.}
  8.  
  9. unit AlphaSAT;
  10.  
  11. interface
  12.     uses
  13. {$ifc UNDEFINED THINK_PASCAL}
  14.         Types, QuickDraw, Events, Windows, Dialogs, Fonts, DiskInit, TextEdit, Traps,{}
  15.         Memory, SegLoad, Scrap, ToolUtils, OSUtils, Menus, Resources, StandardFile,{}
  16.         GestaltEqu, Files, Errors, Devices, QuickDrawText, 
  17. {$endc}
  18.         SAT;
  19.  
  20.     procedure SATFillAlphaRect (box: Rect; port: SATPort);
  21.     procedure SATPaintAlphaRect (box: Rect; port: SATPort; value: Integer);
  22.     procedure SATEraseAlphaRect (box: Rect; port: SATPort);
  23.  
  24. implementation
  25.  
  26.     procedure SATFillAlphaRect (box: Rect; port: SATPort);
  27.         type
  28.             LongPtr = ^Longint;
  29.         var
  30.             savePort: SATPort;
  31.             globalBox: Rect;
  32.             pix: PixMapHandle;
  33.             h, v: Integer;
  34.             pixel: LongPtr;
  35.             maxV, maxH: integer;
  36.     begin
  37.         if not gSAT.colorFlag then
  38.             Exit(SATFillAlphaRect);
  39.         if port.device^^.gdPMap^^.pixelSize <> 32 then
  40.             Exit(SATFillAlphaRect);
  41.  
  42.         SATGetPort(savePort);
  43.         SATSetPort(port);
  44.  
  45.         globalBox := box;
  46.         LocalToGlobal(globalBox.topLeft);
  47.         LocalToGlobal(globalBox.botRight);
  48.         pix := port.device^^.gdPMap;
  49.  
  50.         if box.bottom < port.port^.portRect.bottom then
  51.             maxV := box.bottom - 1
  52.         else
  53.             maxV := port.port^.portRect.bottom - 1;
  54.  
  55.         if box.right < port.port^.portRect.right then
  56.             maxH := box.right - 1
  57.         else
  58.             maxH := port.port^.portRect.right - 1;
  59.  
  60.         if box.left < maxH then
  61.             if box.top < maxV then
  62.                 for v := box.top to maxV do
  63.                     begin
  64.                         pixel := LongPtr(Longint(pix^^.baseAddr) + BitAnd(pix^^.rowBytes, $3fff) * Longint(v) + 4 * box.left);
  65.                         for h := box.left to maxH do
  66.                             begin
  67.                                 pixel^ := BitOr(pixel^, $ff000000); {Fill}
  68.                                 pixel := LongPtr(Longint(pixel) + 4);
  69.                             end;
  70.                     end;
  71.  
  72.         SATSetPort(savePort);
  73.     end; {SATFillAlphaRect}
  74.  
  75.     procedure SATPaintAlphaRect (box: Rect; port: SATPort; value: Integer);
  76.         type
  77.             LongPtr = ^Longint;
  78.         var
  79.             savePort: SATPort;
  80.             globalBox: Rect;
  81.             pix: PixMapHandle;
  82.             h, v: Integer;
  83.             pixel: LongPtr;
  84.             maxV, maxH: integer;
  85.             theValue: Longint;
  86.     begin
  87.         if not gSAT.colorFlag then
  88.             Exit(SATPaintAlphaRect);
  89.         if port.device^^.gdPMap^^.pixelSize <> 32 then
  90.             Exit(SATPaintAlphaRect);
  91.  
  92.         SATGetPort(savePort);
  93.         SATSetPort(port);
  94.  
  95. {Shift value to the right place - the most significant byte}
  96.         theValue := BSL(value, 24);
  97.  
  98.         globalBox := box;
  99.         LocalToGlobal(globalBox.topLeft);
  100.         LocalToGlobal(globalBox.botRight);
  101.         pix := port.device^^.gdPMap;
  102.  
  103.         if box.bottom < port.port^.portRect.bottom then
  104.             maxV := box.bottom - 1
  105.         else
  106.             maxV := port.port^.portRect.bottom - 1;
  107.  
  108.         if box.right < port.port^.portRect.right then
  109.             maxH := box.right - 1
  110.         else
  111.             maxH := port.port^.portRect.right - 1;
  112.  
  113.         if box.left < maxH then
  114.             if box.top < maxV then
  115.                 for v := box.top to maxV do
  116.                     begin
  117.                         pixel := LongPtr(Longint(pix^^.baseAddr) + BitAnd(pix^^.rowBytes, $3fff) * Longint(v) + 4 * box.left);
  118.                         for h := box.left to maxH do
  119.                             begin
  120.                                 pixel^ := BitOr(pixel^, theValue); {Paint}
  121.                                 pixel := LongPtr(Longint(pixel) + 4);
  122.                             end;
  123.                     end;
  124.  
  125.         SATSetPort(savePort);
  126.     end; {SATPaintAlphaRect}
  127.  
  128.     procedure SATEraseAlphaRect (box: Rect; port: SATPort);
  129.         type
  130.             LongPtr = ^Longint;
  131.         var
  132.             savePort: SATPort;
  133.             globalBox: Rect;
  134.             pix: PixMapHandle;
  135.             h, v: Integer;
  136.             pixel: LongPtr;
  137.             maxV, maxH: integer;
  138.     begin
  139.         if not gSAT.colorFlag then
  140.             Exit(SATEraseAlphaRect);
  141.         if port.device^^.gdPMap^^.pixelSize <> 32 then
  142.             Exit(SATEraseAlphaRect);
  143.  
  144.         SATGetPort(savePort);
  145.         SATSetPort(port);
  146.  
  147.         globalBox := box;
  148.         LocalToGlobal(globalBox.topLeft);
  149.         LocalToGlobal(globalBox.botRight);
  150.         pix := port.device^^.gdPMap;
  151.  
  152.         if box.bottom < port.port^.portRect.bottom then
  153.             maxV := box.bottom - 1
  154.         else
  155.             maxV := port.port^.portRect.bottom - 1;
  156.  
  157.         if box.right < port.port^.portRect.right then
  158.             maxH := box.right - 1
  159.         else
  160.             maxH := port.port^.portRect.right - 1;
  161.  
  162.         if box.left < maxH then
  163.             if box.top < maxV then
  164.                 for v := box.top to maxV do
  165.                     begin
  166.                         pixel := LongPtr(Longint(pix^^.baseAddr) + BitAnd(pix^^.rowBytes, $3fff) * Longint(v) + 4 * box.left);
  167.                         for h := box.left to maxH do
  168.                             begin
  169.                                 pixel^ := BitAnd(pixel^, $00ffffff); {Erase}
  170.                                 pixel := LongPtr(Longint(pixel) + 4);
  171.                             end;
  172.                     end;
  173.  
  174.         SATSetPort(savePort);
  175.     end; {SATEraseAlphaRect}
  176.  
  177. end.